package com.zyz.O_网络编程.TCP.聊天室;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author: vick
 * @Date: 2025/4/17
 * @Description:
 * @version: 1.0
 */
public class Send extends Thread{
    private Socket socket;

    public Send(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            //获取输出流，发送数据
            OutputStream outputStream = socket.getOutputStream();
            PrintStream printStream = new PrintStream(outputStream);

            Scanner scanner = new Scanner(System.in);
            //不断输入自己的话，给人服务器发送，服务器转发给其他人
            while (true) {
                System.out.print("我：");
                String str = scanner.nextLine();
                if ("bye".equals(str)) {
                    break;
                }
                printStream.println(str);
            }
            scanner.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
